package cn.com.egova.demoapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.BounceInterpolator;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;

public class LayoutAnimationActivity extends Activity {
    private LinearLayout container;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout_animation);

        container = (LinearLayout) findViewById(R.id.container);
        startLayoutAnimation();
    }



    private void startLayoutAnimation(){
        //1.创建动画(包括动画的各种设定).
        //2.创建LayoutAnimationController
        //3.设置LayoutAnimationController,包括插值器,每个子veiw开始动画的延时,执行顺序等.
        TranslateAnimation transAnimation = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF,
                1.0f,
                Animation.RELATIVE_TO_SELF,
                0.0f,
                Animation.RELATIVE_TO_SELF,
                0f,
                Animation.RELATIVE_TO_SELF,
                0f);
        transAnimation.setDuration(500);
//        transAnimation.setRepeatCount(-1);
//        transAnimation.setRepeatMode(Animation.REVERSE);

        //注意这里创建LayoutAniamtionController时接收的参数是Animation不是Animator,因此不支持属性动画.
        LayoutAnimationController controller = new LayoutAnimationController(transAnimation);
        controller.setDelay(0.6f);
        controller.setInterpolator(new BounceInterpolator());
        controller.setOrder(LayoutAnimationController.ORDER_NORMAL);

        container.setLayoutAnimation(controller);
    }
}
